package com.dc.chat.controller;

import com.dc.chat.app.biz.GrpBiz;
import com.dc.chat.app.service.mp.SensitiveService;
import com.dc.chat.entity.dao.Sensitive;
import com.dc.chat.entity.to.ResponseBean;
import com.dc.chat.entity.to.grp.GetMyMGrpResp;
import com.dc.chat.interceptor.security.Security;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/grp")
public class GrpController {
    @Resource
    GrpBiz grpBiz;
    @Security
    @PostMapping("/addGrp")
    public ResponseBean addGrp(@RequestParam(name="avatar",required = false)MultipartFile file,@RequestParam("grpName") String grpName,@RequestParam("grpDescription") String grpDescription) throws IOException {
        return grpBiz.addGrp(file,grpName,grpDescription);
    }
    @Security
    @PostMapping("/setActiveGrp")
    public void setActiveGrp(@RequestParam("id") Integer id){
        grpBiz.setActiveGrp(id);
    }
    @Security
    @PostMapping("/getMyMGrp")
    public ResponseBean<List<GetMyMGrpResp>> getMyMGrp(){
        return grpBiz.getMyMGrp();
    }
    @Security
    @PostMapping("/delMyMGrp")
    public ResponseBean delMyMGrp(@RequestParam("id") Integer id){
        return grpBiz.delMyMGrp(id);
    }
    @Security
    @PostMapping("/searchGrp")
    public ResponseBean<GetMyMGrpResp> searchGrp(@RequestParam("id") Integer id){
        return grpBiz.searchGrp(id);
    }
    @Security
    @PostMapping("/join")
    public ResponseBean joinGrp(@RequestBody Map map){
        String message = (String) map.get("message");
        Integer id = (Integer) map.get("id");
        return grpBiz.joinGrp(message,id);
    }
    @Security
    @PostMapping("/getGrpVerif")
    public ResponseBean getGrpVerif(){
        return grpBiz.getGrpVerif();
    }
    @Security
    @PostMapping("/agreeJoinGrp")
    public ResponseBean agreeJoinGrp(@RequestParam("id") Integer id) throws JsonProcessingException {
        return grpBiz.agreeJoinGrp(id);
    }
    @Security
    @PostMapping("/disAgreeJoinGrp")
    public ResponseBean disAgreeJoinGrp(@RequestParam("id") Integer id){
        return grpBiz.disAgreeJoinGrp(id);
    }
    @Security
    @PostMapping("/getMyApply")
    public ResponseBean getMyApply(){
        return grpBiz.getMyApply();
    }
    @Security
    @PostMapping("/getMyGrp")
    public ResponseBean getMyGrp(){
        return grpBiz.getMyGrp();
    }
    @Security
    @PostMapping("/getGrpMessage")
    public ResponseBean getGrpMessage(){
        return grpBiz.getGrpMessage();
    }
    @Security
    @PostMapping("/setGrpBack")
    public ResponseBean setGrpBack(@RequestBody Map map){
        Integer id = (Integer) map.get("id");
        String back = (String) map.get("back");
        return grpBiz.setGrpBack(id,back);
    }
    @Security
    @PostMapping("/exitGrp")
    public ResponseBean exitGrp(@RequestParam("id") Integer id){
        return grpBiz.exitGrp(id);
    }
    @Security
    @PostMapping("/inviteUserJoinMyGrp")
    public ResponseBean inviteUserJoinMyGrp(@RequestParam("id") Integer id,@RequestParam("username") String username) throws JsonProcessingException {
        return grpBiz.inviteUserJoinMyGrp(id,username);
    }

}
